package com.xc.pattern.prototype;

/**
 * @author xingchen
 * @description 原型模式
 * @create 2022-08-21 19:41
 */
public class Client {

    public static void main(String[] args) throws CloneNotSupportedException {

        Person person1 = new Person();
        person1.setAge(10);
        person1.setName("星辰");
        person1.getList().add("aaa");
        person1.getList().add("bbb");

        //浅拷贝
        //Person person2 =  person1.clone();
        //深拷贝
        Person person2 = (Person) person1.deepClone();
        person2.setName("望月");
        person2.getList().add("ccc");
        System.out.println("person1=" + person1.getName() + ",age=" + person1.getAge());
        System.out.println("person2=" + person2.getName() + ",age=" + person2.getAge());
    }
}
